// app.ts
App({
    globalData: {
        token: wx.getStorageSync('token') || '',
        userInfo: {},
        tab_value: '/pages/index/index',
        tabData: [
            {
                list: [
                    { value: '/pages/index/index', label: '首页', icon: 'home' },
                    { value: '/pages/my/my', label: '我的', icon: 'user' }
                ]
            }
        ],
        userType: wx.getStorageSync('user-type') || 1 // 1 用户 2 司机 3 管理员
    } as any,
    onLaunch() {
        console.log(this.globalData.userType, '-----onLaunch')
        const type = this.globalData.userType
        if (type == 1) {
            wx.switchTab({
                url: '/pages/index/index'
            })
        }
    },
    async onUnload() {
        await wx.removeStorageSync('isConnectWS')
        await wx.removeStorageSync('userWsID')
        await wx.removeStorageSync('openLocationBackground')
        await wx.closeSocket()
        await clearInterval(wx.getStorageSync('timer'))
        await wx.removeStorageSync('timer')
        wx.onSocketClose(function (res: any) {
            console.log(res, 'WebSocket连接已关闭！')
        })
        wx.stopLocationUpdate({
            success: function () {
                console.log('停止后台定位成功')
            },
            fail: function (res) {
                console.error('停止后台定位失败', res)
            }
        })
    }
})
